﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace _4DJackPot
{
    public partial class Analytics : Dock
    {
        public Analytics()
        {
            InitializeComponent();
        }

        private void bTn_search_Click(object sender, EventArgs e)
        {
            if (this.dTP_from.Value > this.dTP_to.Value)
            {
                MessageBox.Show("Check Date !", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.tB_num1.Text == "" || this.tB_num2.Text == "" || this.tB_num3.Text == "" || this.tB_num4.Text == "")
            {
                MessageBox.Show("Input Number.", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            this.dGv_analytics_sr.Rows.Clear();
            this.dGv_analytics_as.Rows.Clear();
            this.dGv_analytics_summary.Rows.Clear();

            
            
            string[] num = new string[4];
            num[0] = this.tB_num1.Text;
            num[1] = this.tB_num2.Text;
            num[2] = this.tB_num3.Text;
            num[3] = this.tB_num4.Text;

            string[] selectedNum = new String[24];
            string searchNumber = "";
            count = 0;

            if (this.rB_yes.Checked)
            {
                makePermutation(num,selectedNum);
                for (int selectedNumCnt = 0; selectedNumCnt < 24; selectedNumCnt++)
                {
                    if (selectedNum[selectedNumCnt] == null) break;
                    if (selectedNumCnt != 0)
                        searchNumber = searchNumber + ",";
                    searchNumber = searchNumber + selectedNum[selectedNumCnt];
                }
            }
            else 
            {
                searchNumber = this.tB_num1.Text + this.tB_num2.Text + this.tB_num3.Text + this.tB_num4.Text;
                count = 1;
            }
            string selectQueryString =
                @"SELECT GAMES.GAME_ID, NUMBER, GAME_WINNING_NUMBERS.PRIZE_TYPE_ID, DRAW_DATETIME, COMPANIES.COMPANY_ID, COMPANY_NAME, PRIZE_NAME
                FROM GAME_WINNING_NUMBERS, GAMES, COMPANY_GAMES, COMPANIES, PRIZE_TYPES
                WHERE LEFT(GAMES.DRAW_DATETIME,10) >=  '" + this.dTP_from.Value.ToShortDateString() + @"'
                    AND LEFT(GAMES.DRAW_DATETIME,10) <= '" + this.dTP_to.Value.ToShortDateString() + @"'
                AND GAMES.GAME_ID = COMPANY_GAMES.GAME_ID
                AND COMPANIES.COMPANY_ID = COMPANY_GAMES.COMPANY_ID 
                AND GAME_WINNING_NUMBERS.GAME_ID = GAMES.GAME_ID
                AND PRIZE_TYPES.PRIZE_TYPE_ID = GAME_WINNING_NUMBERS.PRIZE_TYPE_ID
                AND NUMBER IN (" + searchNumber + @") 
                ORDER BY DRAW_DATETIME DESC , GAME_WINNING_NUMBERS.PRIZE_TYPE_ID ASC";


            DbConn DbConn = new DbConn();
            DataSet resultReadDataSet = DbConn.ReadQuery(selectQueryString);

            if (resultReadDataSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("There are no results.", "Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            foreach (DataRow row in resultReadDataSet.Tables[0].Rows)
            {
                if(!this.cBx_top3.Checked)
                {
                    if(row["PRIZE_TYPE_ID"].ToString().Equals("1") || row["PRIZE_TYPE_ID"].ToString().Equals("2") || row["PRIZE_TYPE_ID"].ToString().Equals("3"))
                        continue;
                }
                if(!this.cBx_specialPrize.Checked)
                {
                    if (row["PRIZE_TYPE_ID"].ToString().Equals("4"))
                        continue;
                }
                if(!this.cBx_consolationPrize.Checked)
                {
                    if(row["PRIZE_TYPE_ID"].ToString().Equals("5"))
                        continue;
                }

                if(!this.cBx_magnum.Checked)
                {
                    if(row["COMPANY_ID"].ToString().Equals("1"))
                        continue;
                }
                if(!this.cBx_damacai.Checked)
                {
                    if(row["COMPANY_ID"].ToString().Equals("2"))
                        continue;
                }
                if(!this.cBx_toto.Checked)
                {
                    if(row["COMPANY_ID"].ToString().Equals("3"))
                        continue;
                }

                int rowIndex = this.dGv_analytics_sr.RowCount;
                this.dGv_analytics_sr.Rows.Insert(rowIndex);
                string dayString = DateTime.Parse(row["DRAW_DATETIME"].ToString()).DayOfWeek.ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_gameID", rowIndex].Value = row["GAME_ID"].ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_drawdate", rowIndex].Value = row["DRAW_DATETIME"].ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_prize", rowIndex].Value = row["PRIZE_NAME"].ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_company", rowIndex].Value = row["COMPANY_NAME"].ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_number", rowIndex].Value = row["NUMBER"].ToString();
                this.dGv_analytics_sr["dGv_analytics_sr_day", rowIndex].Value = dayString;


            }

            for (int selectedNumCnt = 0; selectedNumCnt < 24; selectedNumCnt++)
            {
                if (selectedNum[selectedNumCnt] == null) break;
                
                selectQueryString =
                @"SELECT " + selectedNum[selectedNumCnt].ToString() + @" AS WINNING_NUMBER, (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND PRIZE_TYPE_ID = 1
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"'
                ) AS FIRST_CNT ,
                (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND PRIZE_TYPE_ID = 2
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"') AS SECOND_CNT ,
                (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND PRIZE_TYPE_ID = 3
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"') AS THIRD_CNT ,
                (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND PRIZE_TYPE_ID = 4
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"') AS SPECIAL_CNT ,
                (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND PRIZE_TYPE_ID = 5
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"') AS CONSOLATION_CNT ,
                (SELECT COUNT(1) AS CNT FROM GAME_WINNING_NUMBERS, GAMES
                WHERE GAMES.GAME_ID = GAME_WINNING_NUMBERS.GAME_ID
                AND NUMBER = "+selectedNum[selectedNumCnt].ToString() +@"
                AND LEFT(GAMES.DRAW_DATETIME,10) >= '"+this.dTP_from.Value.ToShortDateString()+@"'
                 AND LEFT(GAMES.DRAW_DATETIME,10) <= '"+ this.dTP_to.Value.ToShortDateString() +@"') AS TOTAL_CNT 
                FROM (SELECT * FROM USERS WHERE USER_ID = '1')";

                DbConn = new DbConn();
                resultReadDataSet = DbConn.ReadQuery(selectQueryString);

                int rowIndexAs = this.dGv_analytics_as.RowCount;
                this.dGv_analytics_as.Rows.Insert(rowIndexAs);
                string firstPrizeCnt = "-";
                string secondPrizeCnt = "-";
                string thirdPrizeCnt = "-";
                string specialPrizeCnt = "-";
                string consolationPrizeCnt = "-";

                int totalHits = 0;
                if (this.cBx_top3.Checked)
                {
                    firstPrizeCnt = resultReadDataSet.Tables[0].Rows[0]["FIRST_CNT"].ToString();
                    secondPrizeCnt = resultReadDataSet.Tables[0].Rows[0]["SECOND_CNT"].ToString();
                    thirdPrizeCnt = resultReadDataSet.Tables[0].Rows[0]["THIRD_CNT"].ToString();
                    totalHits = totalHits + int.Parse(firstPrizeCnt) + int.Parse(firstPrizeCnt) + int.Parse(firstPrizeCnt);
                }
                if (this.cBx_specialPrize.Checked)
                {
                    specialPrizeCnt = resultReadDataSet.Tables[0].Rows[0]["SPECIAL_CNT"].ToString();
                    totalHits = totalHits + int.Parse(specialPrizeCnt);
                }
                if (this.cBx_consolationPrize.Checked)
                {
                    consolationPrizeCnt = resultReadDataSet.Tables[0].Rows[0]["CONSOLATION_CNT"].ToString();
                    totalHits = totalHits + int.Parse(consolationPrizeCnt);
                }
                

                this.dGv_analytics_as["dGv_analytics_as_firstPrize", rowIndexAs].Value = firstPrizeCnt;
                this.dGv_analytics_as["dGv_analytics_as_secontPrize", rowIndexAs].Value = secondPrizeCnt;
                this.dGv_analytics_as["dGv_analytics_as_thirdPrize", rowIndexAs].Value = thirdPrizeCnt;
                this.dGv_analytics_as["dGv_analytics_as_specialPrize", rowIndexAs].Value = specialPrizeCnt;
                this.dGv_analytics_as["dGv_analytics_as_consolationPrize", rowIndexAs].Value = consolationPrizeCnt;
                this.dGv_analytics_as["dGv_analytics_as_totalhit", rowIndexAs].Value = totalHits.ToString();
                this.dGv_analytics_as["dGv_analytics_as_number", rowIndexAs].Value = resultReadDataSet.Tables[0].Rows[0]["WINNING_NUMBER"].ToString();


            }

            List<int> firstPrizeHitCntList = new List<int>();
            firstPrizeHitCntList.Add(0);
            firstPrizeHitCntList.Add(0);
            firstPrizeHitCntList.Add(0);
            List<int> secondPrizeHitCntList = new List<int>();
            secondPrizeHitCntList.Add(0);
            secondPrizeHitCntList.Add(0);
            secondPrizeHitCntList.Add(0);
            List<int> thirdPrizeHitCntList = new List<int>();
            thirdPrizeHitCntList.Add(0);
            thirdPrizeHitCntList.Add(0);
            thirdPrizeHitCntList.Add(0);
            List<int> specialPrizeHitCntList = new List<int>();
            specialPrizeHitCntList.Add(0);
            specialPrizeHitCntList.Add(0);
            specialPrizeHitCntList.Add(0);
            List<int> consolationPrizeHitCntList = new List<int>();
            consolationPrizeHitCntList.Add(0);
            consolationPrizeHitCntList.Add(0);
            consolationPrizeHitCntList.Add(0);
            List<int> totalPrizeHitCntList = new List<int>();
            totalPrizeHitCntList.Add(0);
            totalPrizeHitCntList.Add(0);
            totalPrizeHitCntList.Add(0);
            
            for(int rowCnt = 0; rowCnt < this.dGv_analytics_sr.Rows.Count; rowCnt++)
            {
                if(this.dGv_analytics_sr["dGv_analytics_sr_company", rowCnt].Value.ToString().Equals("Magnum 4D"))
                {
                    if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("First Prize"))
                    {
                        firstPrizeHitCntList[0] = firstPrizeHitCntList[0] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Second Prize"))
                    {
                        secondPrizeHitCntList[0] = secondPrizeHitCntList[0] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Third Prize"))
                    {
                        thirdPrizeHitCntList[0] = thirdPrizeHitCntList[0] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Special Prize"))
                    {
                        specialPrizeHitCntList[0] = specialPrizeHitCntList[0] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Consolation Prize"))
                    {
                        consolationPrizeHitCntList[0] = consolationPrizeHitCntList[0] + 1;
                    }
                    totalPrizeHitCntList[0] = totalPrizeHitCntList[0] + 1;
                }

                if (this.dGv_analytics_sr["dGv_analytics_sr_company", rowCnt].Value.ToString().Equals("Da Ma Cai 1+3D"))
                {
                    if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("First Prize"))
                    {
                        firstPrizeHitCntList[1] = firstPrizeHitCntList[1] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Second Prize"))
                    {
                        secondPrizeHitCntList[1] = secondPrizeHitCntList[1] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Third Prize"))
                    {
                        thirdPrizeHitCntList[1] = thirdPrizeHitCntList[1] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Special Prize"))
                    {
                        specialPrizeHitCntList[1] = specialPrizeHitCntList[1] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Consolation Prize"))
                    {
                        consolationPrizeHitCntList[1] = consolationPrizeHitCntList[1] + 1;
                    }
                    totalPrizeHitCntList[1] = totalPrizeHitCntList[1] + 1;
                }

                if (this.dGv_analytics_sr["dGv_analytics_sr_company", rowCnt].Value.ToString().Equals("Sports Toto 4D"))
                {
                    if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("First Prize"))
                    {
                        firstPrizeHitCntList[2] = firstPrizeHitCntList[2] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Second Prize"))
                    {
                        secondPrizeHitCntList[2] = secondPrizeHitCntList[2] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Third Prize"))
                    {
                        thirdPrizeHitCntList[2] = thirdPrizeHitCntList[2] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Special Prize"))
                    {
                        specialPrizeHitCntList[2] = specialPrizeHitCntList[2] + 1;
                    }
                    else if (this.dGv_analytics_sr["dGv_analytics_sr_prize", rowCnt].Value.ToString().Equals("Consolation Prize"))
                    {
                        consolationPrizeHitCntList[2] = consolationPrizeHitCntList[2] + 1;
                    }
                    totalPrizeHitCntList[2] = totalPrizeHitCntList[2] + 1;
                }
               
            }

            int summaryCnt = this.dGv_analytics_summary.Rows.Count;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "First Prize";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = firstPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = firstPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = firstPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }
            summaryCnt++;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "Second Prize";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = secondPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = secondPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = secondPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }
            summaryCnt++;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "Third Prize";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = thirdPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = thirdPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = thirdPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }
            summaryCnt++;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "Special Prize";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = specialPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = specialPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = specialPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }
            summaryCnt++;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "Consolation Prize";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = consolationPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = consolationPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = consolationPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }
            summaryCnt++;
            this.dGv_analytics_summary.Rows.Insert(summaryCnt);
            this.dGv_analytics_summary["dGv_analytics_summary_prizeType", summaryCnt].Value = "Total Hits";
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = totalPrizeHitCntList[0].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_magnum", summaryCnt].Value = "-";
            }
            if (this.cBx_damacai.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = totalPrizeHitCntList[1].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_damacai", summaryCnt].Value = "-";
            }
            if (this.cBx_magnum.Checked)
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = totalPrizeHitCntList[2].ToString();
            }
            else
            {
                this.dGv_analytics_summary["dGv_analytics_summary_toto", summaryCnt].Value = "-";
            }

            Cursor.Current = Cursors.Default;

        }

        private int count = 0;

        private void makePermutation(String[] num, String[] selectNum)
        {
            permut(num, 0, selectNum);
        }

        void swap(string[] num, int i, int j)
        {
            string temp = num[i];
            num[i] = num[j];
            num[j] = temp;
        }

        void permut(string[] num, int cur, string[] selectNum)
        {
            if (cur == 3)
            {
                Boolean already = false;
                string temp = num[0] + num[1] + num[2] + num[3];
                for (int i = 0; i < count; i++)
                {
                    if (selectNum[i] == null)
                    {
                        already = false;
                    }
                    else if (selectNum[i].Equals(temp))
                        already = true;
                }
                if (!already)
                    selectNum[count++] = temp;
            }
            else
            {
                for (int i = cur; i < 4; i++)
                {
                    swap(num, cur, i);
                    permut(num, cur + 1, selectNum);
                    swap(num, cur, i);
                }
            }
        }

        private void Analytics_Load(object sender, EventArgs e)
        {
            this.cBx_consolationPrize.Checked = true;
            this.cBx_specialPrize.Checked = true;
            this.cBx_top3.Checked = true;
            this.rB_yes.Checked = true;
            this.cBx_damacai.Checked = true;
            this.cBx_magnum.Checked = true;
            this.cBx_toto.Checked = true;
            dTP_from.Value = DateTime.Now.AddDays(-7);
        }

        //베팅 숫자 값에 숫자가 아닌 다른 값이 들어가는 경우 그 값을 무효화시킨다.
        //숫자가 칸에 들어가면 자동으로 다음 칸으로 옮겨준다.
        private void tB_num1_TextChanged(object sender, EventArgs e)
        {
            Regex regex = new Regex(@"[^\d]+");
            if (!regex.IsMatch(tB_num1.Text))
            {
                tB_num2.Focus();
            }
            else
            {
                tB_num1.Text = "";
            }
        }

        private void tB_num2_TextChanged(object sender, EventArgs e)
        {
            Regex regex = new Regex(@"[^\d]+");
            if (!regex.IsMatch(tB_num2.Text))
            {
                tB_num3.Focus();
            }
            else
            {
                tB_num2.Text = "";
            }
        }

        private void tB_num3_TextChanged(object sender, EventArgs e)
        {
            Regex regex = new Regex(@"[^\d]+");
            if (!regex.IsMatch(tB_num3.Text))
            {
                tB_num4.Focus();
            }
            else
            {
                tB_num3.Text = "";
            }
        }

        private void tB_num4_TextChanged(object sender, EventArgs e)
        {
            Regex regex = new Regex(@"[^\d]+");
            if (!regex.IsMatch(tB_num4.Text))
            {

            }
            else
            {
                tB_num4.Text = "";
            }
        }
    }
}
